package com.cy.网络编程.tcp.test1;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * 客户端
 */
public class Client {
    public static void main(String[] args) throws Exception {
        //创建Socket对象，连接服务器
        Socket socket = new Socket("localhost", 9999);
        //连接成功提示
        System.out.println("客户端连接服务器成功！！！");

        while (true){
            Scanner sc = new Scanner(System.in);
            //客户端发送消息
            OutputStream os = socket.getOutputStream();
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));
            bw.write(sc.nextLine());
            bw.newLine();
            bw.flush();

            //客户端接受消息
            InputStream is = socket.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String s = br.readLine();
            System.out.println("从服务端发送过来的消息是：" + s);
        }



    }
}
